<!DOCTYPE html>
<html lang="en">
<head>
    {{template "header.tpl" .}}
</head>
<body>
<form class="layui-form" action="">
    <div class="mainBox">
        <div class="main-container">
            <div class="main-container">
                <div class="layui-form-item layui-hide">
                    <label class="layui-form-label">编号</label>
                    <div class="layui-input-block">
                        <input type="text" value="{{.role.Id}}" name="id" lay-verify="title"
                               autocomplete="off" placeholder="请输入标题" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">名称</label>
                    <div class="layui-input-block">
                        <input type="text" value="{{.role.Name}}" name="name" lay-verify="title"
                               autocomplete="off" placeholder="请输入标题" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">标识</label>
                    <div class="layui-input-block">
                        <input type="text" value="{{.role.Permission}}" readonly name="permission" lay-verify="title"
                               autocomplete="off" placeholder="请输入标题" class="layui-input">
                    </div>
                </div>
                {{/*<div class="layui-form-item">
                    <label class="layui-form-label">状态</label>
                    <div class="layui-input-block">
                        <input type="radio" name="enable" checked="${sysRole.enable eq '0'}" value="0" title="开启">
                        <input type="radio" name="enable" checked="${sysRole.enable eq '1'}" value="1" title="关闭"
                               checked>
                    </div>
                </div>*/}}
                <div class="layui-form-item">
                    <label class="layui-form-label">角色等级</label>
                    <div class="layui-input-block">
                        <select name="level">
                            <option value="1" {{if eq 1 .role.Level }}selected{{end}}>一级</option>
                            <option value="2" {{if eq 2 .role.Level }}selected{{end}}>二级</option>
                            <option value="3" {{if eq 3 .role.Level }}selected{{end}}>三级</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">数据范围</label>
                    <div class="layui-input-block">
                        <select name="dataScope">
                            <option value="全部" {{if eq "全部" .role.DataScope }}selected{{end}}>全部</option>
                            <option value="本级" {{if eq "本级" .role.DataScope }}selected{{end}}>本级</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">描述</label>
                    <div class="layui-input-block">
                        <textarea placeholder="请输入内容" name="remark" text="{{.role.Remark}}"
                                  class="layui-textarea">{{.role.Remark}}</textarea>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit=""
                    lay-filter="role-update">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="pear-btn pear-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>
{{template "footer.tpl" .}}
<script>
    layui.use(['form', 'jquery'], function () {
        let form = layui.form;
        let $ = layui.jquery;

        form.on('submit(role-update)', function (data) {
            data.field.id = Number(data.field.id)
            data.field.level = Number(data.field.level)
            $.ajax({
                url: '/system/roles',
                data: JSON.stringify(data.field),
                dataType: 'json',
                contentType: 'application/json',
                type: 'put',
                success: function (result) {
                    if (result.status === 200) {
                        layer.msg(result.msg, {icon: 1, time: 1000}, function () {
                            parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                            parent.layui.table.reload("role-table");
                        });
                    } else {
                        layer.msg(result.msg, {icon: 2, time: 1000});
                    }
                }
            })
            return false;
        });
    })
</script>
<script>
</script>
</body>
</html>